package com.wjn.Controller;

import com.wjn.pojo.Result;
import com.wjn.utils.AliOssUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;
@RestController
@CrossOrigin
public class FileUpLoadController {
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws IOException {
        //把文件内容储存到本地硬盘上
        String originalFilename = file.getOriginalFilename();
        //保证文件的名字是唯一的，防止文件覆盖
        String filename = UUID.randomUUID().toString()+originalFilename.substring(originalFilename.lastIndexOf("."));
        String url = AliOssUtil.uploadFile(filename, file.getInputStream());
        // file.transferTo(new File("G:\\桌面\\sportbootlearn\\file"));
        return Result.success(url);
    }
}
